package com.example.verifysdk.creatcode;

import android.content.Context;

import com.example.verifysdk.LogUtil;
import com.example.verifysdk.SpHelper;
import com.example.verifysdk.UploadHelper;

import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 *
 * @author LiuV
 * @date 2017/5/5
 */

public class CreatCodeModel {
    private static final String TAG = "CreatCodeModel";

    public void login(Context context, String partner, String partnerRemark, String totp, Callback callback){
        LogUtil.i(TAG, "---login===" + UploadHelper.getUrl(context) + "api/partner/login");
        RequestBody requestBody = new FormBody.Builder()
                .add("partner", partner)
                .add("partnerRemark", partnerRemark)
                .add("pTotp", totp)
                .build();

        Request request = new Request
                .Builder()
                .url(UploadHelper.getUrl(context) + "api/partner/login")
                .post(requestBody)
                .build();
        new OkHttpClient().newCall(request).enqueue(callback);
    }

    public void applyOnlineSecret(Context context, Callback callback){
        LogUtil.i(TAG, "---applyOnlineSecret===api/generateTOTP");

        Request request = new Request
                .Builder()
                .addHeader("APP_TOKEN", new SpHelper(context).getSdkToken())
                .get()
                .url(UploadHelper.getUrl(context) + "api/generateTOTP")
                .build();
        new OkHttpClient().newCall(request).enqueue(callback);
    }
}
